package ahut2020.day14;

import java.util.Arrays;

//多项式控件
public class Queen8 {
    //递归程序
    static int n = 8;
    static int[] book = new int[n];
    static int[] arr = new int[n];


    static void dfs(int k) {
        if (k >= n) {
            boolean flag = true;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    if (Math.abs(arr[j] - arr[i]) == j - i) {
                        flag = false;
                    }
                }
            if (flag)
                System.out.println(Arrays.toString(arr) + flag);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (book[i] == 1) continue;

            arr[k] = i;

            book[i] = 1;
            dfs(k + 1);
            book[i] = 0;
        }
    }

    public static void main(String[] args) {
        dfs(0);
    }
}
